home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KDChartCustomBox.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  40.0 KB  |  1,044 lines

  1. /* -*- Mode: C++ -*-
  2.    KDChart - a multi-platform charting engine
  3.    */
  4.  
  5. /****************************************************************************
  6.  ** Copyright (C) 2001-2003 Klar├ñlvdalens Datakonsult AB.  All rights reserved.
  7.  **
  8.  ** This file is part of the KDChart library.
  9.  **
  10.  ** This file may be distributed and/or modified under the terms of the
  11.  ** GNU General Public License version 2 as published by the Free Software
  12.  ** Foundation and appearing in the file LICENSE.GPL included in the
  13.  ** packaging of this file.
  14.  **
  15.  ** Licensees holding valid commercial KDChart licenses may use this file in
  16.  ** accordance with the KDChart Commercial License Agreement provided with
  17.  ** the Software.
  18.  **
  19.  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20.  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21.  **
  22.  ** See http://www.klaralvdalens-datakonsult.se/?page=products for
  23.  **   information about KDChart Commercial License Agreements.
  24.  **
  25.  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
  26.  ** licensing are not clear to you.
  27.  **
  28.  **********************************************************************/
  29. #ifndef __KDCHARTCUSTOMBOX_H__
  30. #define __KDCHARTCUSTOMBOX_H__
  31.  
  32. #include <qobject.h>
  33. #include <qtextstream.h>
  34. #include <qfont.h>
  35. #include <qdom.h>
  36. #include "KDChartGlobal.h"
  37. #include "KDChartEnums.h"
  38. #include "KDChartTextPiece.h"
  39.  
  40.  
  41. class KDFrame;
  42.  
  43. // needed because there was no AlignAuto before Qt 3.0
  44. #define KDCHART_AlignAuto 0
  45.  
  46.  
  47. /** \file KDChartCustomBox.h
  48.   \brief Definition of a class for specifying and drawing custom boxes.
  49.   */
  50.  
  51. /**
  52.   Class for specifying and drawing custom boxes.
  53.   */
  54. class KDCHART_EXPORT KDChartCustomBox :public QObject
  55. {
  56.     Q_OBJECT
  57.     friend class KDChartPainter;
  58.     friend class KDChartParams;
  59.  
  60. public:
  61.  
  62.     /**
  63.       Constructor.
  64.       Set default values.
  65.       */
  66.     KDChartCustomBox() :
  67.         _rotation( 0 ),
  68.         _fontSize( -10 ),
  69.         _fontScaleGlobal( true ),
  70.         _deltaX( 0 ),
  71.         _deltaY( 0 ),
  72.         _width(  0 ),
  73.         _height( 0 ),
  74.         _color( Qt::black ),
  75.         _paper( Qt::NoBrush ),
  76.         _anchorArea(  KDChartEnums::AreaInnermost ),
  77.         _anchorPos(   KDChartEnums::PosTopLeft ),
  78.         _anchorAlign( Qt::AlignTop + Qt::AlignLeft ),
  79.         _dataRow( 0 ),
  80.         _dataCol( 0 ),
  81.         _data3rd( 0 ),
  82.         _deltaAlign( KDCHART_AlignAuto ),
  83.         _deltaScaleGlobal( true ),
  84.         _anchorBeingCalculated( false ),
  85.         _parentAxisArea( -1 )
  86.     {
  87.         const KDChartTextPiece piece( 0, "", QFont( "helvetica", 8, QFont::Normal, false ) );
  88.         _content.deepCopy( &piece );
  89.     }
  90.  
  91.     /**
  92.       Constructor.
  93.       Set content and font size but no position/size parameters.
  94.  
  95.       \note If \c fontScaleGlobal is set to true it is not necessary to
  96.       specify the size of the box: if both \c width and \c height are zero
  97.       and \c fontScaleGlobal is true the size of the box will be calculated
  98.       automatically based upon the content size.  In this case the content
  99.       size is interpreted as rich text string - even if the text is NOT
  100.       framed by <tt><qt></tt> and <tt></qt></tt>.
  101.  
  102.       \param content The string or rich text string to be written into the box.
  103.       \param fontSize The size of the font to be used, see explanation above.
  104.       \param fontScaleGlobal If true the font size will be calculated based
  105.       upon the the size of the drawing area, otherwise it will be calculated
  106.       based upon the height of the box.
  107.       */
  108.     KDChartCustomBox( const KDChartTextPiece & content,
  109.                       int fontSize,
  110.                       bool fontScaleGlobal = true ) :
  111.         _rotation( 0 ),
  112.         _fontSize( fontSize ),
  113.         _fontScaleGlobal( fontScaleGlobal ),
  114.         _deltaX( 0 ),
  115.         _deltaY( 0 ),
  116.         _width(  0 ),
  117.         _height( 0 ),
  118.         _color( Qt::black ),
  119.         _paper( Qt::NoBrush ),
  120.         _anchorArea(  KDChartEnums::AreaInnermost ),
  121.         _anchorPos(   KDChartEnums::PosTopLeft ),
  122.         _anchorAlign( Qt::AlignTop + Qt::AlignLeft ),
  123.         _dataRow( 0 ),
  124.         _dataCol( 0 ),
  125.         _data3rd( 0 ),
  126.         _deltaAlign( KDCHART_AlignAuto ),
  127.         _deltaScaleGlobal( true ),
  128.         _anchorBeingCalculated( false ),
  129.          _parentAxisArea( -1 )
  130.     {
  131.         _content.deepCopy( &content );
  132.     }
  133.  
  134.  
  135.     /**
  136.       Constructor.
  137.       Set content and position/size parameters and the color and brush to be used.
  138.  
  139.       \note If \c fontScaleGlobal is set to true it is not necessary to
  140.       specify the size of the box: if both \c width and \c height are zero
  141.       and \c fontScaleGlobal is true the size of the box will be calculated
  142.       automatically based upon the content size.  In this case the content
  143.       size is interpreted as rich text string - even if the text is NOT
  144.       framed by <tt><qt></tt> and <tt></qt></tt>.
  145.  
  146.       \param content The text piece to be displayed.
  147.       \param fontSize If \c fontSize value is greater 0, the value is taken as exact size,
  148.       if \c fontSize is less than 0 it is interpreted as being a per-mille value
  149.       of the size of the drawing area (or of the height of the box in case
  150.       \c fontScaleGlobal is set to false, resp.).
  151.       Normally the actual font size is calculated dynamically in methode paint.
  152.       <b>However</b> if fontSize is zero no calculating will take place but the
  153.       size of the content font is used.
  154.       \param fontScaleGlobal If true the font size will be calculated based
  155.       upon the the size of the drawing area, otherwise it will be calculated
  156.       based upon the height of the box.
  157.       \param deltaX The X distance between the box and its anchor.
  158.       <b>Note: </b> If greater 0, the value is taken as exact offset,
  159.       if less than 0, it is interpreted as being a per-mille value of the
  160.       size of the drawing area (or as percent value of the actual font size
  161.       (as returned by QFontMetrics::lineSpacing() ) if deltaScaleGlobal is FALSE, resp.).
  162.       Actual drawing position/size is calculated dynamically in methode trueRect.
  163.       \param deltaY The Y distance between the box and its anchor.
  164.       \param width The width of the box.
  165.       \param height The height of the box.
  166.       \param color The text color.
  167.       \param paper The brush to be used for the background.
  168.       \param area The area to which the box is to be aligned.
  169.       \param position The anchor position. This is the edge (or
  170.       the corner, resp.) of the area to which
  171.       the box is to be aligned.
  172.       \param align The way how the box is to be aligned to its anchor.
  173.       \param dataRow The row number of the KDChart data region that is to be used
  174.       as anchor area. This parameter is ignored if \c area is not \c AreaChartDataRegion.
  175.       \param dataCol The column number of the KDChart data region that is to be used
  176.       as anchor area. This parameter is ignored if \c area is not \c AreaChartDataRegion.
  177.       \param data3rd The third dimensions number of the KDChart data region that is to be used
  178.       as anchor area. This parameter is ignored if \c area is not \c AreaChartDataRegion
  179.       or if there is no 3-dimensional data structure.
  180.       \param deltaAlign The way how \c deltaX and \deltaY affect the position of the box.
  181.       Leave this parameter to its default value KDCHART_AlignAuto to have the delta values
  182.       used according to the box's main \c align settings, otherwise specify your own
  183.       alignment settings: e.g. right means there will be a gap between the right side of
  184.       the box and its anchor point - if the main \c align parameter is set to right too
  185.       the anchor point will to be outside of the box / if \c align is set to left
  186.       (but the \c deltaAlign to right) the anchor point will be inside the box.
  187.       Possible values for \c deltaAlign are:
  188.       \li \c KDCHART_AlignAuto
  189.       \li \c Qt::AlignLeft | Qt::AlignTop
  190.       \li \c Qt::AlignLeft | Qt::AlignBottom
  191.       \li \c Qt::AlignRight | Qt::AlignTop
  192.       \li \c Qt::AlignRight | Qt::AlignBottom
  193.       Using AlignVCenter or AlignHCenter or AlignCenter does not make sense here:
  194.       center delta alignment will cause KDChart to ignore the respective delta
  195.       settings: deltaX or deltaY or both will become ineffective.
  196.       \param deltaScaleGlobal If true the actual delta X and delta Y values will
  197.       be calculated by \c deltaX and \c deltaY based upon the size of the
  198.       drawing area, otherwise they will be calculated based upon the actual
  199.       font size.
  200.       */
  201.     KDChartCustomBox( const KDChartTextPiece & content,
  202.                       int fontSize,
  203.                       bool fontScaleGlobal,
  204.                       int deltaX,
  205.                       int deltaY,
  206.                       int width,
  207.                       int height,
  208.                       const QColor & color = QColor( Qt::black   ),
  209.                       const QBrush & paper = QBrush( Qt::NoBrush ),
  210.                       uint area                           = KDChartEnums::AreaInnermost,
  211.                       KDChartEnums::PositionFlag position = KDChartEnums::PosTopLeft,
  212.                       uint align                          = Qt::AlignTop + Qt::AlignLeft,
  213.                       uint dataRow = 0,
  214.                       uint dataCol = 0,
  215.                       uint data3rd = 0,
  216.                       uint deltaAlign = KDCHART_AlignAuto,
  217.                       bool deltaScaleGlobal = true,
  218.                       int parentAxis = -1 )
  219.         : _rotation( 0 ),
  220.           _fontSize( fontSize ),
  221.           _fontScaleGlobal( fontScaleGlobal ),
  222.           _deltaX( deltaX ),
  223.           _deltaY( deltaY ),
  224.           _width( width ),
  225.           _height( height ),
  226.           _color( color ),
  227.           _paper( paper ),
  228.           _anchorArea( area ),
  229.           _anchorPos( position ),
  230.           _anchorAlign( align ),
  231.           _dataRow( dataRow ),
  232.           _dataCol( dataCol ),
  233.           _data3rd( data3rd ),
  234.           _deltaAlign( deltaAlign ),
  235.           _deltaScaleGlobal( deltaScaleGlobal ),
  236.           _anchorBeingCalculated( false ),
  237.           _parentAxisArea(  parentAxis )
  238.     {
  239.         _content.deepCopy( &content );
  240.     }
  241.  
  242.  
  243.     /**
  244.       Constructor.
  245.       Use this special constructor to specify a <b>rotated</b> box, reference
  246.       point of the rotation is the anchor specified by the \c area and the
  247.       \c position parameters.
  248.  
  249.       \note If \c fontScaleGlobal is set to true it is not necessary to
  250.       specify the size of the box: if both \c width and \c height are zero
  251.       and \c fontScaleGlobal is true the size of the box will be calculated
  252.       automatically based upon the content size.  In this case the content
  253.       size is interpreted as rich text string - even if the text is NOT
  254.       framed by <tt><qt></tt> and <tt></qt></tt>.
  255.  
  256.       \param rotation The box's rotation angle in degrees (0 .. 360).
  257.       \param content The text piece to be displayed.
  258.       \param fontSize If \c fontSize value is greater 0, the value is taken as exact size,
  259.       if \c fontSize is less than 0 it is interpreted as being a per-mille value
  260.       of the size of the drawing area (or of the height of the box in case
  261.       \c fontScaleGlobal is set to false, resp.).
  262.       Normally the actual font size is calculated dynamically in methode paint.
  263.       <b>However</b> if fontSize is zero no calculating will take place but the
  264.       size of the content font is used.
  265.       \param fontScaleGlobal If true the font size will be calculated based
  266.       upon the the size of the drawing area, otherwise it will be calculated
  267.       based upon the height of the box.
  268.       \param deltaX The X distance between the box and its anchor.
  269.       <b>Note: </b> If greater 0, the value is taken as exact offset,
  270.       if less than 0, it is interpreted as being a per-mille value of the
  271.       width of the drawing area (or as percent value of the actual font size
  272.       (as returned by QFontMetrics::lineSpacing() ) if deltaScaleGlobal is FALSE, resp.).
  273.       Actual drawing position/size is calculated dynamically in method trueRect.
  274.       \param deltaY The Y distance between the box and its anchor.
  275.       <b>Note: </b> If greater 0, the value is taken as exact offset,
  276.       if less than 0, it is interpreted as being a per-mille value of the
  277.       height of the drawing area (or as percent value of the actual font size
  278.       (as returned by QFontMetrics::lineSpacing() ) if deltaScaleGlobal is FALSE, resp.).
  279.       Actual drawing position/size is calculated dynamically in method trueRect.
  280.       \param width The width of the box.
  281.       \param height The height of the box.
  282.       \param color The text color.
  283.       \param paper The brush to be used for the background.
  284.       \param area The area to which the box is to be aligned.
  285.       \param position The anchor position. This is the edge (or
  286.       the corner, resp.) of the area to which the box is to be aligned
  287.       and it is also used as the reference point of the rotation.
  288.       \param align The way how the box is to be aligned to its anchor.
  289.       \param dataRow The row number of the KDChart data region that is to be used
  290.       as anchor area. This parameter is ignored if \c area is not \c AreaChartDataRegion.
  291.       \param dataCol The column number of the KDChart data region that is to be used
  292.       as anchor area. This parameter is ignored if \c area is not \c AreaChartDataRegion.
  293.       \param data3rd The third dimensions number of the KDChart data region that is to be used
  294.       as anchor area. This parameter is ignored if \c area is not \c AreaChartDataRegion
  295.       or if there is no 3-dimensional data structure.
  296.       \param deltaAlign The way how \c deltaX and \deltaY affect the position of the box.
  297.       Leave this parameter to its default value KDCHART_AlignAuto to have the delta values
  298.       used according to the box's main \c align settings, otherwise specify your own
  299.       alignment settings: e.g. Qt::AlignRight means the box will be moved to the left
  300.       (by the amount calculated using the \c deltaX value), so there will be a gap
  301.       between the right side of the box and its anchor point IF the main \c align flag
  302.       is set to Qt::AlignRight too, so the anchor point will to be outside of the
  303.       box then. However if the main \c align flag is set to Qt::AlignLeft the anchor
  304.       point will be inside the box.
  305.       Possible values for \c deltaAlign are:
  306.       \li \c KDCHART_AlignAuto
  307.       \li \c Qt::AlignLeft | Qt::AlignTop
  308.       \li \c Qt::AlignLeft | Qt::AlignBottom
  309.       \li \c Qt::AlignRight | Qt::AlignTop
  310.       \li \c Qt::AlignRight | Qt::AlignBottom
  311.       Using AlignVCenter or AlignHCenter or AlignCenter does not make sense here:
  312.       center delta alignment will cause KDChart to ignore the respective delta
  313.       settings: deltaX or deltaY or both will become ineffective.
  314.       \note Moving of the box due to \c deltaAlign settings is applied after
  315.       the box is rotated: e.g. this means a gap specified by \c deltaAlign = Qt::AlignTop
  316.       gap will actually result in a left gap if the box is rotated by 90 degrees.
  317.       \param deltaScaleGlobal If true the actual delta X and delta Y values will
  318.       be calculated by \c deltaX and \c deltaY based upon the size of the
  319.       drawing area, otherwise they will be calculated based upon the actual
  320.       font size.
  321.       */
  322.     KDChartCustomBox( int rotation,
  323.                       const KDChartTextPiece & content,
  324.                       int fontSize,
  325.                       bool fontScaleGlobal,
  326.                       int deltaX,
  327.                       int deltaY,
  328.                       int width,
  329.                       int height,
  330.                       const QColor & color = QColor( Qt::black   ),
  331.                       const QBrush & paper = QBrush( Qt::NoBrush ),
  332.                       uint area                           = KDChartEnums::AreaInnermost,
  333.                       KDChartEnums::PositionFlag position = KDChartEnums::PosTopLeft,
  334.                       uint align                          = Qt::AlignTop + Qt::AlignLeft,
  335.                       uint dataRow = 0,
  336.                       uint dataCol = 0,
  337.                       uint data3rd = 0,
  338.                       uint deltaAlign = KDCHART_AlignAuto,
  339.                       bool deltaScaleGlobal = true,
  340.                       int parentAxis = -1 )
  341.         : _rotation( rotation ),
  342.           _fontSize( fontSize ),
  343.           _fontScaleGlobal( fontScaleGlobal ),
  344.           _deltaX( deltaX ),
  345.           _deltaY( deltaY ),
  346.           _width( width ),
  347.           _height( height ),
  348.           _color( color ),
  349.           _paper( paper ),
  350.           _anchorArea( area ),
  351.           _anchorPos( position ),
  352.           _anchorAlign( align ),
  353.           _dataRow( dataRow ),
  354.           _dataCol( dataCol ),
  355.           _data3rd( data3rd ),
  356.           _deltaAlign( deltaAlign ),
  357.           _deltaScaleGlobal( deltaScaleGlobal ),
  358.           _anchorBeingCalculated( false ),
  359.           _parentAxisArea(  parentAxis )
  360.     {
  361.         _content.deepCopy( &content );
  362.     }
  363.  
  364.  
  365.     /**
  366.       Creates a DOM element node that represents a custom box for use
  367.       in a DOM document.
  368.  
  369.       \param document the DOM document to which the node will belong
  370.       \param parent the parent node to which the new node will be appended
  371.       \param elementName the name of the new node
  372.       \param custombox the custom box to be represented
  373.       */
  374.     static void createCustomBoxNode( QDomDocument& document,
  375.                                      QDomNode& parent,
  376.                                      const QString& elementName,
  377.                                      const KDChartCustomBox* custombox );
  378.  
  379.     /**
  380.       Reads data from a DOM element node that represents a custom box
  381.       object and fills a KDChartCustomBox object with the data.
  382.  
  383.       \param element the DOM element to read from
  384.       \param settings the custom box object to read the data into
  385.       */
  386.     static bool readCustomBoxNode( const QDomElement& element,
  387.                                    KDChartCustomBox& custombox );
  388.  
  389. public slots: // PENDING(blackie) merge slots sections.
  390.  
  391.     float trueFontSize( double areaWidthP1000,
  392.                         double areaHeightP1000,
  393.                         int rectHeight ) const;
  394.     int trueFontLineSpacing( double areaWidthP1000,
  395.                              double areaHeightP1000,
  396.                              int rectHeight ) const;
  397.     int trueRectAlignX(const QRect& rect) const;
  398.     int trueRectAlignY(const QRect& rect) const;
  399.     void getTrueShift( double areaWidthP1000,
  400.                        double areaHeightP1000,
  401.                        int rectHeight,
  402.                        int& dX,
  403.                        int& dY )const;
  404.  
  405.  
  406.     /**
  407.       Return the actual rectangle which to draw box into.
  408.  
  409.       \note When ever possible, use this method, instead of the other trueRect(), that
  410.       has no \c QPainter parameter. Passing a QPainter will give you more exact results.
  411.  
  412.       \param painter The QPainter to be used.
  413.       \param anchor The anchor point which the box is to be aligned to.
  414.       This can be any point within the painter drawing area but you
  415.       will probably compute a point using anchorArea(), anchorPosition(), anchorAlign()
  416.       (and dataRow(), dataCol(), data3rd() when dealing with KDChart data regions, resp.)
  417.       \param areaWidthP1000 The thousands part of the logical width
  418.       of the area to be used for drawing.
  419.       \param areaHeightP1000 The thousands part of the logical height
  420.       of the area to be used for drawing.
  421.       */
  422.     QRect trueRect( QPainter * painter,
  423.        QPoint anchor, double areaWidthP1000, double areaHeightP1000 ) const ;
  424.  
  425.     /**
  426.       Return the actual rectangle which to draw box into.
  427.  
  428.       \param anchor The anchor point which the box is to be aligned to.
  429.       This can be any point within the painter drawing area but you
  430.       will probably compute a point using anchorArea(), anchorPosition(), anchorAlign()
  431.       (and dataRow(), dataCol(), data3rd() when dealing with KDChart data regions, resp.)
  432.       \param areaWidthP1000 The thousands part of the logical width
  433.       of the area to be used for drawing.
  434.       \param areaHeightP1000 The thousands part of the logical height
  435.       of the area to be used for drawing.
  436.       */
  437.     virtual QRect trueRect( QPoint anchor,
  438.                             double areaWidthP1000,
  439.                             double areaHeightP1000 ) const ;
  440.  
  441.     /**
  442.       Paints the box.
  443.  
  444.       \param painter The QPainter to be used for drawing.
  445.       \param anchor The anchor point which the box is to be aligned to.
  446.       This can be any point within the painter drawing area but you
  447.       will probably compute a point using anchorArea(), anchorPosition(), anchorAlign()
  448.       (and dataRow(), dataCol(), data3rd() when dealing with KDChart data regions, resp.)
  449.       \param areaWidthP1000 The thousands part of the drawing area width.
  450.       \param areaHeightP1000 The thousands part of the drawing area height.
  451.       \param color The text color to be used.
  452.       \param paper The brush to be used for the background.
  453.       \param rect The rectangle to be drawn into. If empty the rectangle will be
  454.       calculated dynamically based upon the \c x, \c y, \c width, \c height values
  455.       (that were set via Constructor or via setPosAndSize) and based upon the
  456.       logical height (or width, resp.) of the painters drawing area.
  457.       */
  458.     virtual void paint( QPainter* painter,
  459.                         QPoint anchor,
  460.                         double areaWidthP1000,
  461.                         double areaHeightP1000,
  462.                         const KDFrame* frame     = 0,
  463.                         const QRect&   frameRect = QRect(),
  464.                         const QColor * color = 0,
  465.                         const QBrush * paper = 0 ) const ;
  466.  
  467.     /**
  468.       Specifies the rotation angle of the box in degrees (0..360).
  469.       */
  470.     void setRotation( int rotation )
  471.     {
  472.         _rotation = rotation;
  473.     }
  474.  
  475.     /**
  476.       Specifies the text piece content to be drawn.
  477.       */
  478.     void setContent( const KDChartTextPiece & content )
  479.     {
  480.         _content.deepCopy( &content );
  481.     }
  482.  
  483.     /**
  484.       Specifies the font size to be used.
  485.  
  486.       \note If \c fontScaleGlobal is set to true it is not necessary to
  487.       specify the size of the box: if both \c width and \c height are zero
  488.       and \c fontScaleGlobal is true the size of the box will be calculated
  489.       automatically based upon the content size.  In this case the content
  490.       size is interpreted as rich text string - even if the text is NOT
  491.       framed by <tt><qt></tt> and <tt></qt></tt>.
  492.  
  493.       \param fontSize If \c fontSize value is greater 0, the value is taken as exact size,
  494.       if \c fontSize is less than 0 it is interpreted as being a per-mille value
  495.       of the size of the drawing area (or of the height of the box in case
  496.       \c fontScaleGlobal is set to false, resp.).
  497.       Normally the actual font size is calculated dynamically in methode paint.
  498.       <b>However</b> if fontSize is zero no calculating will take place but the
  499.       size of the content font is used.
  500.       \param fontScaleGlobal If true the font size will be calculated based
  501.       upon the the size of the drawing area, otherwise it will be calculated
  502.       based upon the height of the box.
  503.       */
  504.     void setFontSize( int fontSize, bool fontScaleGlobal )
  505.     {
  506.         _fontSize        = fontSize;
  507.         _fontScaleGlobal = fontScaleGlobal;
  508.     }
  509.  
  510.     /**
  511.       Specifies the area to which the box is to be aligned.
  512.       */
  513.     void setAnchorArea( uint area )
  514.     {
  515.         _anchorArea = area;
  516.     }
  517.  
  518.     /**
  519.       Specifies the anchor position.
  520.       This is the edge (or the corner, resp.) of the area
  521.       to which the box is to be aligned.
  522.       */
  523.     void setAnchorPosition( KDChartEnums::PositionFlag position )
  524.     {
  525.         // Note if you change the parameters here, then you must also change them in wrappers/KDChartCustomBoxWrapper.h
  526.         _anchorPos = position;
  527.     }
  528.  
  529.     /**
  530.       Specifies the way how the box is to be aligned to its anchor.
  531.       */
  532.     void setAnchorAlign( uint align )
  533.     {
  534.         _anchorAlign = align;
  535.     }
  536.  
  537.     /**
  538.       Specifies the row number of the KDChart data region that is to be used
  539.       as anchor area. This value is ignored if anchorArea is not \c AreaChartDataRegion.
  540.       */
  541.     void setDataRow( uint dataRow )
  542.     {
  543.         _dataRow = dataRow;
  544.     }
  545.  
  546.     /**
  547.       Specifies the column number of the KDChart data region that is to be used
  548.       as anchor area. This value is ignored if anchorArea is not \c AreaChartDataRegion.
  549.       */
  550.     void setDataCol( uint dataCol )
  551.     {
  552.         _dataCol = dataCol;
  553.     }
  554.  
  555.     /**
  556.       Specifies the third dimensions number of the KDChart data region that is to be used
  557.       as anchor area. This value is ignored if anchorArea is not \c AreaChartDataRegion
  558.       or if there is no 3-dimensional data structure.
  559.       */
  560.     void setData3rd( uint data3rd )
  561.     {
  562.         _data3rd = data3rd;
  563.     }
  564.  
  565.     /**
  566.       Specifies the distance between the box and the anchor point and
  567.       specifies the size of the box.
  568.  
  569.       \param deltaX The X distance between the box and its anchor.
  570.       <b>Note: </b> If greater 0, the value is taken as exact offset,
  571.       if less than 0, it is interpreted as being a per-mille value of the
  572.       size of the drawing area (or as percent value of the actual font size
  573.       (as returned by QFontMetrics::lineSpacing() ) if deltaScaleGlobal is FALSE, resp.).
  574.       Actual drawing position/size is calculated dynamically in methode trueRect.
  575.       \param deltaY The Y distance between the box and its anchor.
  576.       \param width The width of the drawing region.
  577.       \param height The height of the drawing region.
  578.       \param deltaAlign the way how the values specified for deltaX and/or deltaY
  579.       affect the position of the box.
  580.       \param deltaScaleGlobal If true the actual delta X and delta Y values will
  581.       be calculated by \c deltaX and \c deltaY based upon the size of the
  582.       drawing area, otherwise they will be calculated based upon the actual
  583.       font size.
  584.  
  585.       \sa setDistance, setSize, setDeltaAlign, setDeltaScale
  586.       */
  587.     void setDistanceAndSize( int deltaX,
  588.                              int deltaY,
  589.                              int width,
  590.                              int height,
  591.                              uint deltaAlign = KDCHART_AlignAuto,
  592.                              bool deltaScaleGlobal = true )
  593.     {
  594.         _deltaX = deltaX;
  595.         _deltaY = deltaY;
  596.         _width = width;
  597.         _height = height;
  598.         _deltaAlign = deltaAlign;
  599.         _deltaScaleGlobal = deltaScaleGlobal;
  600.     }
  601.  
  602.     /**
  603.       Specifies the distance between the box and the anchor point.
  604.  
  605.       \note If \c fontScaleGlobal is set to true it is not necessary to
  606.       specify the size of the box: if both \c width and \c height are zero
  607.       and \c fontScaleGlobal is true the size of the box will be calculated
  608.       automatically based upon the content size.  In this case the content
  609.       size is interpreted as rich text string - even if the text is NOT
  610.       framed by <tt><qt></tt> and <tt></qt></tt>.
  611.  
  612.       \param deltaX The X distance between the box and its anchor.
  613.       <b>Note: </b> If greater 0, the value is taken as exact offset,
  614.       if less than 0, it is interpreted as being a per-mille value of the
  615.       size of the drawing area (or as percent value of the actual font size
  616.       (as returned by QFontMetrics::lineSpacing() ) if deltaScaleGlobal is FALSE, resp.).
  617.       Actual drawing position/size is calculated dynamically in methode trueRect.
  618.       \param deltaY The Y distance between the box and its anchor.
  619.       \param align the way how the values specified for deltaX and/or deltaY
  620.       affect the position of the box.
  621.       \param deltaScaleGlobal If true the actual delta X and delta Y values will
  622.       be calculated by \c deltaX and \c deltaY based upon the size of the
  623.       drawing area, otherwise they will be calculated based upon the actual
  624.       font size.
  625.  
  626.       \sa setDistanceAndSize, setSize, setDeltaAlign, setDeltaScale
  627.       */
  628.     void setDistance( int deltaX,
  629.                       int deltaY,
  630.                       uint align = KDCHART_AlignAuto,
  631.                       bool deltaScaleGlobal = true )
  632.     {
  633.         _deltaX = deltaX;
  634.         _deltaY = deltaY;
  635.         _deltaAlign = align;
  636.         _deltaScaleGlobal = deltaScaleGlobal;
  637.     }
  638.  
  639.     /**
  640.       Specifies the way how the values specified for deltaX and/or deltaY
  641.       affect the position of the box.
  642.  
  643.       Set this to KDHART_KDCHART_AlignAuto to have the delta values
  644.       used according to the box's main \c align settings, otherwise specify your own
  645.       alignment settings: e.g. right means there will be a gap between the right side of
  646.       the box and its anchor point - if the main \c align parameter is set to right too
  647.       the anchor point will to be outside of the box / if \c align is set to left
  648.       (but the \c deltaAlign to right) the anchor point will be inside the box.
  649.       Possible values for \c deltaAlign are:
  650.       \li \c KDCHART_AlignAuto
  651.       \li \c Qt::AlignLeft | Qt::AlignTop
  652.       \li \c Qt::AlignLeft | Qt::AlignBottom
  653.       \li \c Qt::AlignRight | Qt::AlignTop
  654.       \li \c Qt::AlignRight | Qt::AlignBottom
  655.       Using AlignVCenter or AlignHCenter or AlignCenter does not make sense here:
  656.       center delta alignment will cause KDChart to ignore the respective delta
  657.       settings: deltaX or deltaY or both will become ineffective.
  658.       \note Moving of the box due to \c deltaAlign settings is applied after
  659.       the box is rotated: e.g. this means a gap specified by \c deltaAlign = Qt::AlignTop
  660.       gap will actually result in a left gap if the box is rotated by 90 degrees.
  661.       \param deltaScaleGlobal If true the actual delta X and delta Y values will
  662.       be calculated by \c deltaX and \c deltaY based upon the size of the
  663.       drawing area, otherwise they will be calculated based upon the actual
  664.       font size.
  665.  
  666.       \sa setDeltaScale, setDistance, setDistanceAndSize, deltaAlign
  667.       */
  668.     void setDeltaAlign( uint align,
  669.                         bool deltaScaleGlobal = true )
  670.     {
  671.         _deltaAlign = align;
  672.         _deltaScaleGlobal = deltaScaleGlobal;
  673.     }
  674.  
  675.     /**
  676.       Specifies the way how the distance between the box and its anchor
  677.       will be calculated.
  678.  
  679.       \param deltaScaleGlobal If true the actual delta X and delta Y values will
  680.       be calculated by \c deltaX and \c deltaY based upon the size of the
  681.       drawing area, otherwise they will be calculated based upon the actual
  682.       font size.
  683.  
  684.       \sa setDeltaAlign, setDistance, setDistanceAndSize, deltaAlign
  685.       */
  686.     void setDeltaScale( bool deltaScaleGlobal )
  687.     {
  688.         _deltaScaleGlobal = deltaScaleGlobal;
  689.     }
  690.  
  691.     /**
  692.       Specifies the size of the box.
  693.  
  694.       \note If \c fontScaleGlobal is set to true it is not necessary to
  695.       specify the size of the box: if both \c width and \c height are zero
  696.       and \c fontScaleGlobal is true the size of the box will be calculated
  697.       automatically based upon the content size.  In this case the content
  698.       size is interpreted as rich text string - even if the text is NOT
  699.       framed by <tt><qt></tt> and <tt></qt></tt>.
  700.  
  701.       \param width The width of the box.
  702.       <b>Note:</b> If greater 0, the value is taken as exact offset,
  703.       if less than 0, it is interpreted as being a per-mille value
  704.       of the logical height (or width, resp.) of the area to be used for drawing.
  705.       Actual drawing position/size is calculated dynamically in methode trueRect.
  706.       \param height The height of the box.
  707.  
  708.       \sa setDistance, setDistanceAndSize, setDeltaAlign
  709.       */
  710.     void setSize( int width, int height )
  711.     {
  712.         _width = width;
  713.         _height = height;
  714.     }
  715.  
  716.     /**
  717.       Specifies the text color to be used.
  718.  
  719.       \param color The text color.
  720.       */
  721.     void setColor( QColor color )
  722.     {
  723.         _color = color;
  724.     }
  725.  
  726.     /**
  727.       Specifies the brush to be used for the background.
  728.  
  729.       \param paper The brush to be used for the background.
  730.       */
  731.     void setPaper( const QBrush & paper )
  732.     {
  733.         _paper = paper;
  734.     }
  735.  
  736.     /**
  737.       Returns the rotation angle of the box in degrees (0..360).
  738.       */
  739.     int rotation() const
  740.     {
  741.         return _rotation;
  742.     }
  743.  
  744.     /**
  745.       Returns the text piece content that is to be drawn.
  746.       */
  747.     const KDChartTextPiece & content() const
  748.     {
  749.         return _content;
  750.     }
  751.  
  752.     /**
  753.       Returns the font size to be used.
  754.  
  755.       \note If fontSize value is greater 0, the value is taken as exact size,
  756.       if less than 0, it is interpreted as being a per-mille value of the logical
  757.       height (or width, resp.) of the area to be used for drawing.
  758.       Normally the actual font size is calculated dynamically in methode paint.
  759.       <b>However</b> if fontSize is zero no calculating will take place but the
  760.       size of the content font is used.
  761.       */
  762.     int fontSize() const
  763.     {
  764.         return _fontSize;
  765.     }
  766.  
  767.     /**
  768.       Returns the way how the font size is calculated <b>if</b> fontSize() is negative.
  769.  
  770.       If true the font size will be calculated based upon the the size of the drawing
  771.       area, otherwise it will be calculated based upon the height of the box.
  772.       */
  773.     bool fontScaleGlobal() const
  774.     {
  775.         return _fontScaleGlobal;
  776.     }
  777.  
  778.     /**
  779.       Returns the area to which the box is to be aligned.
  780.       */
  781.     uint anchorArea() const
  782.     {
  783.         return _anchorArea;
  784.     }
  785.  
  786.     /**
  787.       Returns the anchor position.
  788.       This is the edge (or the corner, resp.) of the area
  789.       to which the box is to be aligned.
  790.       */
  791.     KDChartEnums::PositionFlag anchorPosition() const
  792.     {
  793.         return _anchorPos;
  794.     }
  795.  
  796.     /**
  797.       Returns the way how the box is to be aligned to its anchor.
  798.       */
  799.     uint anchorAlign() const
  800.     {
  801.         return _anchorAlign;
  802.     }
  803.  
  804.     /**
  805.       Returns the row number of the KDChart data region that is to be used
  806.       as anchor area. You should use this if anchorArea is \c AreaChartDataRegion
  807.       to find out the data region which the box is to be aligned to.
  808.       */
  809.     uint dataRow() const
  810.     {
  811.         return _dataRow;
  812.     }
  813.  
  814.     /**
  815.       Returns the column number of the KDChart data region that is to be used
  816.       as anchor area. You should use this if anchorArea is \c AreaChartDataRegion
  817.       to find out the data region which the box is to be aligned to.
  818.       */
  819.     uint dataCol() const
  820.     {
  821.         return _dataCol;
  822.     }
  823.  
  824.     /**
  825.       Returns the third dimensions number of the KDChart data region that is to be used
  826.       as anchor area. You should use this if anchorArea is \c AreaChartDataRegion
  827.       and if there is a 3-dimensional data structure
  828.       to find out the data region which the box is to be aligned to.
  829.       */
  830.     uint data3rd() const
  831.     {
  832.         return _data3rd;
  833.     }
  834.  
  835.     /**
  836.       Returns the X distance between the box and its anchor.
  837.       <b>Note: </b> If greater 0, the value is taken as exact offset,
  838.       if less than 0, it is interpreted as being a per-mille value of the
  839.       size of the drawing area (or as percent value of the actual font size
  840.       (as returned by QFontMetrics::lineSpacing() ) if deltaScaleGlobal is FALSE, resp.).
  841.       Actual drawing position/size is calculated dynamically in methode trueRect.
  842.  
  843.       \sa deltaY, deltaAlign, deltaScaleGlobal
  844.       */
  845.     int deltaX() const
  846.     {
  847.         return _deltaX;
  848.     }
  849.  
  850.     /**
  851.       Returns the Y distance between the box and its anchor.
  852.       <b>Note: </b> If greater 0, the value is taken as exact offset,
  853.       if less than 0, it is interpreted as being a per-mille value of the
  854.       size of the drawing area (or as percent value of the actual font size
  855.       (as returned by QFontMetrics::lineSpacing() ) if deltaScaleGlobal is FALSE, resp.).
  856.       Actual drawing position/size is calculated dynamically in methode trueRect.
  857.  
  858.       \sa deltaX, deltaAlign, deltaScaleGlobal
  859.       */
  860.     int deltaY() const
  861.     {
  862.         return _deltaY;
  863.     }
  864.  
  865.     /**
  866.       Returns the way how the values specified for deltaX and/or deltaY
  867.       affect the position of the box.
  868.  
  869.       \sa setDeltaAlign, deltaX, deltaY, deltaScaleGlobal
  870.       */
  871.     uint deltaAlign() const
  872.     {
  873.         return _deltaAlign;
  874.     }
  875.  
  876.     /**
  877.       Returns the way how the distance between the box and its anchor
  878.       is calculated.
  879.  
  880.       \sa setDeltaScaleGlobal, deltaX, deltaY, deltaAlign
  881.       */
  882.     bool deltaScaleGlobal() const
  883.     {
  884.         return _deltaScaleGlobal;
  885.     }
  886.  
  887.     /**
  888.       Returns the width of the region where
  889.       to draw the box. <b>Note:</b> If greater 0, the value is the exact offset,
  890.       if less than 0, it is interpreted as being a per-mille value
  891.       of the logical height (or width, resp.) of the area to be used for drawing.
  892.       Actual drawing position/size is calculated dynamically in methode trueRect.
  893.       */
  894.     int width() const
  895.     {
  896.         return _width;
  897.     }
  898.  
  899.     /**
  900.       Returns the height of the region where
  901.       to draw the box. <b>Note:</b> If greater 0, the value is the exact offset,
  902.       if less than 0, it is interpreted as being a per-mille value
  903.       of the logical height (or width, resp.) of the area to be used for drawing.
  904.       Actual drawing position/size is calculated dynamically in methode trueRect.
  905.       */
  906.     int height() const
  907.     {
  908.         return _height;
  909.     }
  910.  
  911.     /**
  912.       Returns the text color.
  913.       */
  914.     QColor color() const
  915.     {
  916.         return _color;
  917.     }
  918.  
  919.     /**
  920.       Returns the background brush.
  921.       */
  922.     const QBrush & paper() const
  923.     {
  924.         return _paper;
  925.     }
  926.  
  927. public:
  928.     /**
  929.       Destructor. Only defined to have it virtual.
  930.       */
  931.     virtual ~KDChartCustomBox();
  932.  
  933.     /**
  934.       Copy the settings of box \c source into this box.
  935.  
  936.       \note Use this method instead of using the assignment operator.
  937.  
  938.       \sa clone
  939.       */
  940.     void deepCopy( const KDChartCustomBox* source );
  941.  
  942.  
  943.     /**
  944.       Create a new box on the heap, copy the settings stored by
  945.       this box into the newly created box and return
  946.       the pointer to the new box.
  947.  
  948.       \note Use this method instead of using the copy constructor.
  949.  
  950.       \sa deepCopy
  951.       */
  952.     const KDChartCustomBox* clone() const;
  953.  
  954. private:
  955.     KDChartCustomBox( const KDChartCustomBox& ) : QObject(0) {}
  956.  
  957. protected:
  958.     /**
  959.       Internal routine for recursion handling.
  960.       Note: This is a const methode changing NO VITAL information
  961.             of the box but setting an internal, temporary flag.
  962.       */
  963.     void setInternalFlagAnchorBeingCalculated( bool flag ) const
  964.     {
  965.         KDChartCustomBox* that = const_cast<KDChartCustomBox*>(this);
  966.         that->_anchorBeingCalculated = flag;
  967.     }
  968.     /**
  969.       Internal routine for recursion handling.
  970.       */
  971.     bool anchorBeingCalculated() const
  972.     {
  973.         return _anchorBeingCalculated;
  974.     }
  975.  
  976.     void setParentAxisArea( int parentAxis ) const
  977.     {
  978.         KDChartCustomBox* that = const_cast<KDChartCustomBox*>(this);
  979.         that->_parentAxisArea = parentAxis;
  980.     }
  981.  
  982.     int parentAxisArea() const
  983.     {
  984.         return _parentAxisArea;
  985.     }
  986.  
  987. private:
  988.     int              _rotation;
  989.     KDChartTextPiece _content;
  990.     int              _fontSize;
  991.     bool             _fontScaleGlobal;
  992.     // Values to be transformed into a real rect at painting time.
  993.     // If greater 0, values are exact, if less than 0, values are in per-mille
  994.     // of the size of the drawing area.
  995.     int _deltaX;
  996.     int _deltaY;
  997.     int _width;
  998.     int _height;
  999.  
  1000.     QColor _color;
  1001.     QBrush _paper;
  1002.  
  1003.     uint                       _anchorArea;
  1004.     KDChartEnums::PositionFlag _anchorPos;
  1005.     uint                       _anchorAlign;
  1006.     uint _dataRow;
  1007.     uint _dataCol;
  1008.     uint _data3rd;
  1009.     uint                       _deltaAlign;
  1010.     bool                       _deltaScaleGlobal;
  1011.     //
  1012.     // The following flag is NOT to be saved/restored in a file.
  1013.     //
  1014.     // Being a TEMPORARY flag preventing circular recursion
  1015.     // it must be set to   f a l s e
  1016.     // after loading a KDChartCustomBox from a file.
  1017.     bool _anchorBeingCalculated;
  1018.     int                        _parentAxisArea;
  1019. };
  1020.  
  1021.  
  1022. /**
  1023.   Writes the KDChartCustomBox object p as an XML document to the text stream s.
  1024.  
  1025.   \param s the text stream to write to
  1026.   \param p the KDChartCustomBox object to write
  1027.   \return the text stream after the write operation
  1028.   */
  1029. //QTextStream& operator<<( QTextStream& s, const KDChartCustomBox& p );
  1030.  
  1031.  
  1032. /**
  1033.   Reads the an XML document from the text stream s into the
  1034.   KDChartCustomBox object p
  1035.  
  1036.   \param s the text stream to read from
  1037.   \param p the KDChartCustomBox object to read into
  1038.   \return the text stream after the read operation
  1039.   */
  1040. //QTextStream& operator>>( QTextStream& s, KDChartCustomBox& p );
  1041.  
  1042.  
  1043. #endif
  1044.